import React, { useEffect, useState } from 'react';
import { Button, Checkbox, Form, Input, Select, DatePicker } from 'antd';
import type { DatePickerProps } from 'antd';
import { useHistory, useParams, useLocation } from 'react-router-dom';
import service from '../../utils/service';
const { TextArea } = Input;
const { Option } = Select;


function Assign() {
    let params = useParams();
    const { id } = useParams<{ id: string }>();
    let history = useHistory()

    useEffect(() => {
        service({
            url: `http://localhost:3000/shenheList/${id}`,
        }).then(res => {
            setitem(res.data)
        })

    })
    const [item, setitem] = useState([])

    const onFinish: any = (values: any) => {
        console.log(values);
        service({
            url: `http://localhost:3000/shenheList/${id}`,
            method: 'DELETE'
        }).then(res => {
            service({
                url: 'http://localhost:3000/chuliList',
                method: 'POST',
                data: {
                    id: id,
                    ...values,
                    ...item
                }
            }).then(res => {
                alert('指派成功')
                history.push("/Main/dangerManagement")
            })
        })
    }

    return (
        <>
            <div>
                隐患确认信息
            </div>
            <Form
                name="basic"
                labelCol={{ span: 8 }}
                wrapperCol={{ span: 16 }}
                style={{ maxWidth: 600 }}
                initialValues={{ remember: true }}
                onFinish={onFinish}
                autoComplete="off"
            >
                <Form.Item
                    label="处理人"
                    name="name2"
                >
                    <Input />
                </Form.Item>
                <Form.Item label="隐患类型:" name='type'>
                    <Select defaultValue="隐患类型" style={{ width: '500px' }}>
                        <Option value="校园三防建设">校园三防建设</Option>
                        <Option value="校园食品卫生">校园食品卫生</Option>
                        <Option value="校园消防安全">校园消防安全</Option>
                        <Option value="体艺设施设备">体艺设施设备</Option>
                    </Select>
                </Form.Item>
                <Form.Item label="隐患级别:" name='leave'>
                    <Select defaultValue="隐患类型" style={{ width: '500px' }}>
                        <Option value="1">全部</Option>
                        <Option value="重大隐患">重大隐患</Option>
                        <Option value="一般隐患">一般隐患</Option>
                    </Select>
                </Form.Item>
                <Form.Item
                    label="处理日期"
                    name="timeover"
                >
                   <Input placeholder='请输入预计结束时间'></Input>
                </Form.Item>
                <Form.Item label=" 隐患描述: " name='desc'>
                    <TextArea rows={4} style={{ width: '500px' }} />
                </Form.Item>
                <Form.Item wrapperCol={{ offset: 8, span: 16 }}>
                    <Button type="primary" htmlType="submit">
                        指派
                    </Button>
                </Form.Item>
            </Form>
        </>
    );
}

export default Assign;